const db = require('../db/connMysql');

const mysql_tool = require('../util/mysql_tool');

const studentDao = {
    /*
     * 分页获取学生列表
     */
    async getStudentList(start, num) {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let sql = `SELECT
                               s.studentId AS studentId,
                               s.cardId AS cardId,
                               s.name AS name,
                               f.name AS facultyName,
                               c.name AS className,
                               u.username AS teacherName,
                               w.name AS warningLevelName,
                               DATE_FORMAT(s.createTime, '%Y-%m-%d') AS createTime
                           FROM
                               Students AS s
                           LEFT JOIN Classes AS c ON s.classId = c.classId
                           LEFT JOIN Facultys AS f ON c.facultyId = f.facultyId
                           LEFT JOIN Teachers AS t ON c.teacherId = t.teacherId
                           LEFT JOIN Users AS u ON t.uid = u.uid
                           LEFT JOIN WarningLevels AS w ON s.warningLevelId = w.warningLevelId
                           LIMIT ?, ?`;
                connection.query(sql, [start, num], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    // /*
    //  * 获取所有学生列表 - 不分页
    //  */
    // async getStudentList() {
    //     let result = await new Promise((resolve, reject) => {
    //         db.getConnection((err, connection) => {
    //             if (err) {
    //                 // 连不上数据库
    //                 reject(err);
    //                 return ;
    //             }
    //             let sql = `SELECT
    //                            s.studentId AS studentId,
    //                            s.cardId AS cardId,
    //                            s.name AS name,
    //                            f.name AS facultyName,
    //                            c.name AS className,
    //                            u.username AS teacherName,
    //                            w.name AS warningLevelName,
    //                            DATE_FORMAT(s.createTime, '%Y年%m月%d日') AS createTime
    //                        FROM
    //                            Students AS s
    //                        LEFT JOIN Classes AS c ON s.classId = c.classId
    //                        LEFT JOIN Facultys AS f ON c.facultyId = f.facultyId
    //                        LEFT JOIN Teachers AS t ON s.teacherId = t.teacherId
    //                        LEFT JOIN Users AS u ON t.uid = u.uid
    //                        LEFT JOIN WarningLevels AS w ON s.warningLevelId = w.warningLevelId
    //             `;
    //             connection.query(sql, [], function (err, result) {
    //                 if (err) {
    //                     // 连上数据库之后，执行sql时发生错误
    //                     reject(err);
    //                     return ;
    //                 }
    //                 connection.release();
    //                 resolve(result);
    //             });
    //         });
    //     });
    //     return result;
    // },
    /*
     * 获取学生详细信息
     */
    async getStudentInfo(studentId) {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let sql = `SELECT
                               s.studentId AS studentId,
                               s.cardId AS cardId,
                               s.name AS name,
                               w.name AS warningLevelName,
                               s.sex AS sex,
                               DATE_FORMAT(s.birthday, '%Y-%m-%d') AS birthday,
                               f.name AS facultyName,
                               c.name AS className,
                               s.phone AS phone,
                               u.username AS teacherName,
                               s.address AS address,
                               s.f_occupation AS fatherOccupation,
                               s.m_occupation AS motherOccupation,
                               s.familyEcon AS familyEcon,
                               s.familyStruct AS familyStruct,
                               s.isOnlyChild AS isOnlyChild,
                               s.hasFamilyHistoryIll AS hasFamilyHistoryIll,
                               s.academic AS academic
                           FROM
                               Students AS s
                           LEFT JOIN Classes AS c ON s.classId = c.classId
                           LEFT JOIN Facultys AS f ON c.facultyId = f.facultyId
                           LEFT JOIN Teachers AS t ON c.teacherId = t.teacherId
                           LEFT JOIN Users AS u ON t.uid = u.uid
                           LEFT JOIN WarningLevels AS w ON s.warningLevelId = w.warningLevelId
                           WHERE
                               s.studentId = ?
                           LIMIT 1`;
                connection.query(sql, [studentId], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    /*
     * 查询所有学生的列表
     */
    async getAllStudentList() {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let sql = `SELECT
                               s.studentId AS studentId,
                               s.cardId AS cardId,
                               s.name AS name,
                               f.name AS facultyName,
                               c.name AS className,
                               u.username AS teacherName,
                               w.name AS warningLevelName,
                               DATE_FORMAT(s.createTime, '%Y-%m-%d') AS createTime
                           FROM
                               Students AS s
                           LEFT JOIN Classes AS c ON s.classId = c.classId
                           LEFT JOIN Facultys AS f ON c.facultyId = f.facultyId
                           LEFT JOIN Teachers AS t ON c.teacherId = t.teacherId
                           LEFT JOIN Users AS u ON t.uid = u.uid
                           LEFT JOIN WarningLevels AS w ON s.warningLevelId = w.warningLevelId`;
                connection.query(sql, [], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    /*
     * 查询自己所在学院的所有学生的列表
     */
    async getAllStudentListOfFaculty(uid) {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let sql = `SELECT
                               s.studentId AS studentId,
                               s.cardId AS cardId,
                               s.name AS name,
                               f.name AS facultyName,
                               c.name AS className,
                               u.username AS teacherName,
                               w.name AS warningLevelName,
                               DATE_FORMAT(s.createTime, '%Y-%m-%d') AS createTime
                           FROM
                               Students AS s
                           LEFT JOIN Classes AS c ON s.classId = c.classId
                           LEFT JOIN Facultys AS f ON c.facultyId = f.facultyId
                           LEFT JOIN Teachers AS t ON c.teacherId = t.teacherId
                           LEFT JOIN Users AS u ON t.uid = u.uid
                           LEFT JOIN WarningLevels AS w ON s.warningLevelId = w.warningLevelId
                           where c.facultyId = (select facultyId from Users where uid = ?)`;
                connection.query(sql, [uid], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    /*
     * 查询所有学生的列表
     */
    async getAllStudentListLimit() {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let sql = `SELECT
                               s.studentId AS studentId,
                               s.cardId AS cardId,
                               s.name AS name,
                               f.name AS facultyName,
                               c.name AS className,
                               u.username AS teacherName,
                               w.name AS warningLevelName,
                               DATE_FORMAT(s.createTime, '%Y-%m-%d') AS createTime
                           FROM
                               Students AS s
                           LEFT JOIN Classes AS c ON s.classId = c.classId
                           LEFT JOIN Facultys AS f ON c.facultyId = f.facultyId
                           LEFT JOIN Teachers AS t ON c.teacherId = t.teacherId
                           LEFT JOIN Users AS u ON t.uid = u.uid
                           LEFT JOIN WarningLevels AS w ON s.warningLevelId = w.warningLevelId
                           LIMIT 200`;
                connection.query(sql, [], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    /*
     * 查询自己所在学院的所有学生的列表
     */
    async getAllStudentListOfFacultyLimit(uid) {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let sql = `SELECT
                               s.studentId AS studentId,
                               s.cardId AS cardId,
                               s.name AS name,
                               f.name AS facultyName,
                               c.name AS className,
                               u.username AS teacherName,
                               w.name AS warningLevelName,
                               DATE_FORMAT(s.createTime, '%Y-%m-%d') AS createTime
                           FROM
                               Students AS s
                           LEFT JOIN Classes AS c ON s.classId = c.classId
                           LEFT JOIN Facultys AS f ON c.facultyId = f.facultyId
                           LEFT JOIN Teachers AS t ON c.teacherId = t.teacherId
                           LEFT JOIN Users AS u ON t.uid = u.uid
                           LEFT JOIN WarningLevels AS w ON s.warningLevelId = w.warningLevelId
                           where c.facultyId = (select facultyId from Users where uid = ?)
                           LIMIT 200`;
                connection.query(sql, [uid], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    /*
     * 在自己所在学院搜索学生接口
     */
    async searchStudentListOfFacultyLimit(uid, name, cardId, className, facultyId, tname, warningLevelId) {
        let searchStr = '';
        if (name) {
            searchStr += ` and s.name like '%${name}%'`;
        }
        if (cardId) {
            searchStr += ` and s.cardId like '%${cardId}%'`;
        }
        if (className) {
            searchStr += ` and c.name like '%${className}%'`;
        }
        if (facultyId) {
            searchStr += ` and f.facultyId = ${facultyId}`;
        }
        if (tname) {
            searchStr += ` and u.username like '%${tname}%'`;
        }
        if (warningLevelId) {
            searchStr += ` and w.warningLevelId = ${warningLevelId}`;
        }
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let sql = `SELECT
                               s.studentId AS studentId,
                               s.cardId AS cardId,
                               s.name AS name,
                               f.name AS facultyName,
                               c.name AS className,
                               u.username AS teacherName,
                               w.name AS warningLevelName,
                               DATE_FORMAT(s.createTime, '%Y-%m-%d') AS createTime
                           FROM
                               Students AS s
                           LEFT JOIN Classes AS c ON s.classId = c.classId
                           LEFT JOIN Facultys AS f ON c.facultyId = f.facultyId
                           LEFT JOIN Teachers AS t ON c.teacherId = t.teacherId
                           LEFT JOIN Users AS u ON t.uid = u.uid
                           LEFT JOIN WarningLevels AS w ON s.warningLevelId = w.warningLevelId
                           where c.facultyId = (select facultyId from Users where uid = ?) ${searchStr}
                           LIMIT 1000`;
                connection.query(sql, [uid], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    /*
     * 全局搜索学生接口
     */
    async searchStudentListLimit(uid, name, cardId, className, facultyId, tname, warningLevelId) {
        let searchStr = '';
        if (name) {
            searchStr += ` and s.name like '%${name}%'`;
        }
        if (cardId) {
            searchStr += ` and s.cardId like '%${cardId}%'`;
        }
        if (className) {
            searchStr += ` and c.name like '%${className}%'`;
        }
        if (facultyId) {
            searchStr += ` and f.facultyId = ${facultyId}`;
        }
        if (tname) {
            searchStr += ` and u.username like '%${tname}%'`;
        }
        if (warningLevelId) {
            searchStr += ` and w.warningLevelId = ${warningLevelId}`;
        }
        if (searchStr) {
            searchStr = 'where' + searchStr.substring(4);
        }
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let sql = `SELECT
                               s.studentId AS studentId,
                               s.cardId AS cardId,
                               s.name AS name,
                               f.name AS facultyName,
                               c.name AS className,
                               u.username AS teacherName,
                               w.name AS warningLevelName,
                               DATE_FORMAT(s.createTime, '%Y-%m-%d') AS createTime
                           FROM
                               Students AS s
                           LEFT JOIN Classes AS c ON s.classId = c.classId
                           LEFT JOIN Facultys AS f ON c.facultyId = f.facultyId
                           LEFT JOIN Teachers AS t ON c.teacherId = t.teacherId
                           LEFT JOIN Users AS u ON t.uid = u.uid
                           LEFT JOIN WarningLevels AS w ON s.warningLevelId = w.warningLevelId
                           ${searchStr} LIMIT 1000`;
                connection.query(sql, [], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    /*
     * 新增学生信息接口
     */
    async addStudentInfo(studentData) {
        let sql = `insert into Students(
                cardId,
                name,
                classId,
                sex,
                phone,
                birthday,
                socialPlatform,
                address,
                f_occupation,
                m_occupation,
                familyEcon,
                familyStruct,
                isOnlyChild,
                hasFamilyHistoryIll,
                academic,
                warningLevelId
            ) VALUES (
                ?, ?, (select classId from Classes where name=?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
                (select warningLevelId from WarningLevels where name=? LIMIT 1)
            )`;
        let data = [
            studentData.cardId, studentData.name, studentData.className, studentData.sex, studentData.phone,
            studentData.birthday, studentData.socialPlatform, studentData.address, studentData.fatherOccupation, studentData.motherOccupation,
            studentData.familyEcon, studentData.familyStruct, studentData.isOnlyChild, studentData.hasFamilyHistoryIll, studentData.academic,
            "无预警"
        ];
        return mysql_tool.execSql(sql, data);
    },
    /*
     * 修改学生信息
     */
    async updateStudentInfo(data) {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let updateData = [
                    data.cardId, data.name, data.classId, data.sex, data.phone, 
                    data.birthday, data.socialPlatform, data.address,
                    data.fatherOccupation, data.motherOccupation, data.familyEcon, data.familyStruct,
                    data.isOnlyChild, data.hasFamilyHistoryIll, data.academic, data.studentId
                ];
                let sql = `update Students
                           set
                               cardId=?,
                               name=?,
                               classId=?,
                               sex=?,
                               phone=?,
                               birthday=?,
                               socialPlatform=?,
                               address=?,
                               f_occupation=?,
                               m_occupation=?,
                               familyEcon=?,
                               familyStruct=?,
                               isOnlyChild=?,
                               hasFamilyHistoryIll=?,
                               academic=?
                           where studentId=?`;
                connection.query(sql, updateData, function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    async updateStudentWarningLevel(data) {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let updateData = [ data.warningLevelId, data.studentId ];
                let sql = `update Students set warningLevelId=? where studentId=?`;
                connection.query(sql, updateData, function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    /*
     * 使用学生的姓名和学号查询到学生的id
     */
    async findStudentIdByNameAndCardId(cardId, name) {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let sql = `select studentId from Students where cardId=? AND name=? LIMIT 1`;
                connection.query(sql, [cardId, name], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    /*
     * 获取所有班级的接口
     */
    async getAllClassList() {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let sql = `select classId as id, name from Classes`;
                connection.query(sql, [], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    /*
     * 获取所有学院的接口
     */
    async getAllFacultys() {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let sql = `select facultyId as id, name from Facultys`;
                connection.query(sql, [], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    /*
     * 获取所有预警等级的接口
     */
    async getAllWarningLevelList() {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let sql = `select warningLevelId as id, name from WarningLevels`;
                connection.query(sql, [], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    async exportStudentInfo(studentIdList) {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let allStudentIdTable = 'select ';
                for (let i = 0; i < studentIdList.length; i++) {
                    if (i == 0) {
                        allStudentIdTable += (studentIdList[i] + ' AS studentId ');
                    } else {
                        allStudentIdTable += ('UNION ALL SELECT ' + studentIdList[i] + ' ');
                    }
                }
                console.log('【导出学生信息 组织sql语句完毕的时间1】', Date.now());
                let sql = `SELECT
                               s.studentId as studentId,
                               s.name as studentName,
                               s.cardId as cardId,
                               f.name as faculty,
                               c.name as class,
                               s.phone as phone,
                               s.socialPlatform as socialPlatform,
                               s.address as address,
                               s.f_occupation as f_occupation,
                               s.m_occupation as m_occupation,
                               s.familyEcon as familyEcon,
                               s.familyStruct as familyStruct,
                               s.isOnlyChild as isOnlyChild,
                               s.hasFamilyHistoryIll as hasFamilyHistoryIll,
                               s.academic as academic,
                               u.username as teacher,
                               u.phone as teacherPhone,
                               w.name as warningLevel,
                               DATE_FORMAT(lci.startTime, '%Y-%m-%d %H:%i:%s') as CensusInterviewDate,
                               ulci.username as CensusInterviewTeacher,
                               lci.question1 as CensusInterviewQuestion1,
                               lci.question2 as CensusInterviewQuestion2,
                               lci.question3 as CensusInterviewQuestion3,
                               lci.question4 as CensusInterviewQuestion4,
                               lci.question5 as CensusInterviewQuestion5,
                               lci.question6 as CensusInterviewQuestion6,
                               lci.question7 as CensusInterviewQuestion7,
                               co.centerOpinion as CensusInterviewCenterOpinion,
                               DATE_FORMAT(lct.startTime, '%Y-%m-%d %H:%i:%s') as ConsultationDate,
                               uclct.username as ConsultationTeacher,
                               lct.subjectiveDescription as ConsultationSDescription,
                               lct.objectiveDescription as ConsultationODescription,
                               lct.counselorAssessment as counselorAssessment,
                               DATE_FORMAT(ldi.startTime, '%Y-%m-%d %H:%i:%s') as DailyInterviewTime,
                               ldi.interviewContent as DailyInterviewContent,
                               ldi.isWarning as DailyInterviewisWarning,
                               DATE_FORMAT(lmr.time, '%Y-%m-%d %H:%i:%s') as medicalTime,
                               lmr.hospital as medicalhospital,
                               it.illType as medicalType,
                               lmr.note as medicalNote,
                               DATE_FORMAT(lc.time, '%Y-%m-%d %H:%i:%s') as harmTime,
                               lc.address as harmAddress,
                               ct.name as harmType,
                               lc.note as harmNote
                           from (${allStudentIdTable}) as sl
                           left join Students as s on sl.studentId = s.studentId
                           left join Classes as c on s.classId = c.classId
                           left join Facultys as f on c.facultyId = f.facultyId
                           left join Teachers as t on c.teacherId = t.teacherId
                           left join Users as u on t.uid = u.uid
                           left join WarningLevels as w on s.warningLevelId = w.warningLevelId
                           left join LastCensusInterview as lci on sl.studentId = lci.studentId
                           left join Users as ulci on lci.counselorId = ulci.uid
                           left join CenterOpinion as co on lci.centerOpinionId = co.centerOpinionId
                           left join LastConsultation as lct on sl.studentId = lct.studentId
                           left join Counselors as clct on lct.counselorId = clct.counselorId
                           left join Users as uclct on clct.uid = uclct.uid
                           left join LastDailyInterview as ldi on sl.studentId = ldi.studentId
                           left join LastMedicalRecord as lmr on sl.studentId = lmr.studentId
                           left join IllTypes as it on lmr.illTypeId = it.illTypeId
                           left join LastCrisis as lc on sl.studentId = lc.studentId
                           left join CrisisTypes as ct on lc.crisisTypeId = ct.crisisTypeId`;
                // let sql2 = `WITH InnerQuery AS (${sql})
                //             SELECT DISTINCT studentId
                //             FROM InnerQuery`;
                console.log('【导出学生信息 组织sql语句完毕的时间2】', Date.now());
                connection.query(sql, [], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        console.log(err);
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    /*
     * 获取所有学生的学号
     */
    async getAllCardIdList() {
        let result = await new Promise((resolve, reject) => {
            db.getConnection((err, connection) => {
                if (err) {
                    // 连不上数据库
                    connection.release();
                    reject(err);
                    return ;
                }
                let sql = `select cardId as id from Students`;
                connection.query(sql, [], function (err, result) {
                    if (err) {
                        // 连上数据库之后，执行sql时发生错误
                        connection.release();
                        reject(err);
                        return ;
                    }
                    connection.release();
                    resolve(result);
                });
            });
        });
        return result;
    },
    /*
     * 判断某个学号的学生是否已经存在
     */
    async findStudentIdByCardId(cardId) {
        let sql = `select studentId from Students where cardId = ?`;
        let data = [ cardId ];
        return mysql_tool.execSql(sql, data);
    }
};

module.exports = studentDao;